package com.ly.mpayment.persist.service.downorderlog;

import java.io.Serializable;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.ly.mpayment.persist.entity.DownOrderLog;
import com.ly.mpayment.persist.hibernate.Page;
import com.ly.mpayment.persist.service.AbstractService;

@Service
public class DownOrderLogServiceImpl extends AbstractService<DownOrderLog, Serializable> implements IDownOrderLogService{

	@Override
	public DownOrderLog findById(String id) {
		return this.findUnique("select d from DownOrderLog d where d.downorderloguuid = ?", id);
	}

	@Override
	public boolean addDownorderlog(DownOrderLog dow) {
		if(dow != null){
			this.saveOrUpdate(dow);
			return true;
		}
		return false;
	}

	@Override
	public boolean updateDownorderlog(DownOrderLog dow) {
		if(dow != null){
			this.saveOrUpdate(dow);
			return true;
		}
		return false;
	}

	@Override
	public Page<DownOrderLog> findPageDownorderlog(Map<String, Object> parameters, int start, int pageSize) {
		String hql = "select d from DownOrderLog d left join fetch d.userLog  left join fetch d.downRechargeFlow where 1 = 1 #[ and d.downRechargeFlow.dowonphonenum = :phoneNum]# #[ and d.downRechargeFlow.userFlow.useruuid = :useruuid]#";
		if(parameters.containsKey(":starttime")){
			hql += " and  d.createtime >= '"+parameters.get(":starttime").toString()+"'";
			parameters.remove(":starttime");
		}

		if(parameters.containsKey(":endtime")){
			hql += " and  d.createtime <= '"+parameters.get(":endtime").toString()+"'";
			parameters.remove(":endtime");
		}
		hql += " order by d.createtime desc";
		return this.findPageByNamed(hql, parameters, start, pageSize);
	}

}
